package com.joolun.web.controller.logistics;

import com.joolun.common.core.domain.AjaxResult;
import com.joolun.mall.dto.JDCancelOrderResultDTO;
import com.joolun.mall.dto.JDDeliveryParamDTO;
import com.joolun.mall.dto.JDEstimatedFreightsParamDTO;
import com.joolun.mall.dto.JDFreightResultDTO;
import com.joolun.mall.service.LogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author quyang
 * @description 物流接口控制器
 * @date 2022/1/2
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/logistics")
@Api(value = "logistics", tags = "物流接口")
public class LogisticsController {

    @Autowired
    private LogisticsService logisticsAbstractService;

    @ApiOperation("查询费用和时效")
    @PostMapping("/queryEstimatedFreights")
    public AjaxResult queryEstimatedFreights(@RequestBody JDEstimatedFreightsParamDTO body) {
        List<JDFreightResultDTO> freights = logisticsAbstractService.queryEstimatedFreights(body);
        return AjaxResult.success(freights);
    }

    @ApiOperation("下单")
    @PostMapping("/delivery")
    public AjaxResult delivery(@RequestBody JDDeliveryParamDTO body) {
        AjaxResult result = logisticsAbstractService.delivery(body);
        return result;
    }

    @ApiOperation("取消运单")
    @GetMapping("/cancelOrder")
    public AjaxResult cancelOrder(@RequestParam Integer logisticsId, String deliveryNo) {
        JDCancelOrderResultDTO result = logisticsAbstractService.cancelOrder(logisticsId, deliveryNo);
        return AjaxResult.success(result);
    }

}
